package bdz.projects.sc.core
{
	
	/**
	 * ...
	 * @author ...
	 */
	public class SCItemObject {
		public var subset:SCItemList;
		public var parent:SCItemList;
		public var name:String;
		public var type:String;
		public var standard:String;
		public var classic:String;
		public var grid:String;
		public var gridleft:String;
		public var validSelections:Array;
		public var escapable:Boolean = false;
		public function SCItemObject(xm:XML, p:SCItemList):void {
			parent = p;
			if (xm.children().length() > 0) {
				subset = new SCItemList(xm.map.item);
			}
			name = xm.@name;
			type = xm.@type;
			standard = xm.@standard;
			classic = xm.@classic;
			grid = xm.@grid;
			gridleft = xm.@gridleft;
			escapable = xm.@escapable == "true";
			validSelections = new Array();
			var cnt:Number = 0;
			for each(var io:SCItemObject in subset) {
				if (io.type != "nothing") {
					validSelections[cnt] = io;
					cnt++;
				}
				
			}
		}
		public function findSubset(prop:String, key:String):SCItemObject {
			for each(var io:SCItemObject in validSelections) {
				if (io[prop] == key) {
					return io;
				}
			}
			return null;
		}
		public function getRandomSubset():SCItemObject {
			var rand:Number = Math.floor(Math.random() * validSelections.length);
			var randItem:SCItemObject = validSelections[rand];
			
			if (randItem.validSelections != null && randItem.validSelections.length > 0) {
				return randItem.getRandomSubset();
			}
			
			return randItem;
		}
		
	}
	
}